/**
 * Created by wangjian on 2017/10/20.
 */

app.component('mProjectPlan', {
    transclude: true,
    bindings: {
        projectPlanName: "@",
        selectTab: "@",
        type: "@",
    },
    controller: function ($scope, $stateParams, $rootScope,$element, $attrs) {
        var ctrl = this;
        ctrl.info = {};
        $scope.info = {};
        //产品设计页需要根据权限进行控制
        $scope.info.isPdm = $rootScope.isUserCanOperateByRole("pdm");

        ctrl.info.tabArray = [
            {
                "id": 0,
                "label": "概述",
                "active": "summary" == ctrl.selectTab ? "active" : "",
                "disabled": false,
                "show": true,
                "type": "summary"
            },
            {
                "id": 1,
                "label": "产品设计",
                "active": "demand" == ctrl.selectTab ? "active" : "",
                "disabled": false,
                "show": true,
                "type": "demand"
            },
            {
                "id": 3,
                "label": "任务列表",
                "active": "planTask" == ctrl.selectTab ? "active" : "",
                "disabled": false,
                "show": true,
                "type": "planTask"
            },
            {
                "id": 11,
                "label": "甘特图",
                "active": "gantt" == ctrl.selectTab ? "active" : "",
                "disabled": true,
                "show": true,
                "type": "gantt"
            },
            {
                "id": 5,
                "label": "前端开发",
                "active": "ui_dev" == ctrl.selectTab ? "active" : "",
                "disabled": true,
                "show": true,
                "type": "ui_dev"
            },
            {
                "id": 6,
                "label": "后台开发",
                "active": "develop" == ctrl.selectTab ? "active" : "",
                "disabled": true,
                "show": true,
                "type": "develop"
            },
            {
                "id": 7,
                "label": "QA测试",
                "active": "qa_test" == ctrl.selectTab ? "active" : "",
                "disabled": true,
                "show": true,
                "type": "qa_test"
            },
            {
                "id": 8,
                "label": "进展报告",
                "active": "report" == ctrl.selectTab ? "active" : "",
                "disabled": true,
                "show": true,
                "type": "report"
            },
            {
                "id": 9,
                "label": "问题",
                "active": "question" == ctrl.selectTab ? "active" : "",
                "disabled": true,
                "show": true,
                "type": "question"
            },
            {
                "id": 10,
                "label": "变更记录",
                "active": "change_record" == ctrl.selectTab ? "active" : "",
                "disabled": true,
                "show": true,
                "type": "change_record"
            }
        ];
        if(ctrl.type == "req") {
            ctrl.info.tabArray = [
                {
                    "id": 0,
                    "label": "概述",
                    "active": "summary" == ctrl.selectTab ? "active" : "",
                    "disabled": false,
                    "show": true,
                    "type": "summary"
                },
                {
                    "id": 1,
                    "label": "用户故事列表",
                    "active": "demand" == ctrl.selectTab ? "active" : "",
                    "disabled": false,
                    "show": $scope.info.isPdm,
                    "type": "demand"
                },
                {
                    "id": 11,
                    "label": "思维导图",
                    "active": "mindMap" == ctrl.selectTab ? "active" : "",
                    "disabled": false,
                    "show": $scope.info.isPdm,
                    "type": "mindMap"
                },
                {
                    "id": 2,
                    "label": "场景设计",
                    "active": "flow" == ctrl.selectTab ? "active" : "",
                    "disabled": false,
                    "show": $scope.info.isPdm,
                    "type": "flow"
                },
                {
                    "id": 3,
                    "label": "功能点设计",
                    "active": "feature" == ctrl.selectTab ? "active" : "",
                    "disabled": false,
                    "show": $scope.info.isPdm,
                    "type": "feature"
                },
                {
                    "id": 4,
                    "label": "用户手册变更",
                    "active": "userManualGuide" == ctrl.selectTab ? "active" : "",
                    "disabled": false,
                    "show": $scope.info.isPdm,
                    "type": "userManualGuide"
                },
                {
                    "id": 5,
                    "label": "报表",
                    "active": "reportForm" == ctrl.selectTab ? "active" : "",
                    "disabled": false,
                    "show": $scope.info.isPdm,
                    "type": "reportForm"
                },
                {
                    "id": 6,
                    "label": "上线要求",
                    "active": "remarks" == ctrl.selectTab ? "active" : "",
                    "disabled": false,
                    "show": $scope.info.isPdm,
                    "type": "remarks"
                },
                {
                    "id": 7,
                    "label": "上线公告",
                    "active": "notice" == ctrl.selectTab ? "active" : "",
                    "disabled": false,
                    "show": $scope.info.isPdm,
                    "type": "notice"
                },
                {
                    "id": 8,
                    "label": "宣讲预览",
                    "active": "demo" == ctrl.selectTab ? "active" : "",
                    "disabled": false,
                    "show": true,
                    "type": "demo"
                },
                {
                    "id": 10,
                    "label": "宣讲记录",
                    "active": "debunker" == ctrl.selectTab ? "active" : "",
                    "disabled": false,
                    "show": $scope.info.isPdm,
                    "type": "debunker"
                },
                {
                    "id": 9,
                    "label": "编排",
                    "active": "layout" == ctrl.selectTab ? "active" : "",
                    "disabled": false,
                    "show": $scope.info.isPdm,
                    "type": "layout"
                },
            ];
        };
        ctrl.tabClick = function (tab) {
            if(tab.disabled){
                return;
            }
            if(ctrl.type == "req") {
                window.location.href = "#/app/req/" + tab.type + "/" + $stateParams.reqId;
            } else {
                window.location.href = "#/app/plan/" + tab.type + "/" + $stateParams.type + "/" + $stateParams.id;
            }
        };
    },
    templateUrl: getTemplateUrl('matrix/component/tpl/mProjectPlan.html')
});